using System;
using System.Collections.Generic;
using System.Text;
using BitMango;
using BitMango.Diagnostics;
using HCP.Responses;
using HCP.SimpleJSON;
using JsonFx.Json;

namespace HCP.Requests
{
	public class CallAdManagerMethod : JobRequest
	{
		public CallAdManagerMethod(JSONClass json) : base(json)
		{
		}

		public string AdType
		{
			get
			{
				return base.Data["p1"];
			}
		}

		public string Zone
		{
			get
			{
				return base.Data["p2"];
			}
		}

		public string Method
		{
			get
			{
				return base.Data["mname"];
			}
		}

		public override JobResponse Process()
		{
			if (this.builder == null)
			{
				this.builder = new StringBuilder();
			}
			else
			{
				this.builder.Length = 0;
			}
			bool flag = false;
			string method = this.Method;
			if (method != null)
			{
				if (method == "show_ad")
				{
					this.ShowAd();
					goto IL_70;
				}
			}
			Debugger.LogError("Unknown method name in AdManagerV4 : " + this.Method);
			IL_70:
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary["result"] = flag.ToString();
			JsonWriterSettings jsonWriterSettings = new JsonWriterSettings();
			jsonWriterSettings.PrettyPrint = false;
			using (JsonWriter jsonWriter = new JsonWriter(this.builder, jsonWriterSettings))
			{
				jsonWriter.Write(dictionary);
			}
			return new StringResponse(this.builder.ToString());
		}

		private void ShowAd()
		{
			string adType = this.AdType;
			if (adType != null)
			{
				if (!(adType == "interstitial"))
				{
					if (adType == "video")
					{
						Context.AdManager.ShowVideo(this.Zone, null, 0);
					}
				}
				else
				{
					Context.AdManager.ShowInterstitial(this.Zone, true, null);
				}
			}
		}

		public StringBuilder builder;
	}
}
